package com.silverhaze.diamond.client.data;

import com.silverhaze.diamond.common.entity.SystemUser;
import com.silverhaze.commons.utils.crypt.MD5;
import com.silverhaze.diamond.client.utils.db.ServiceDataSource;

import java.util.Date;

/**
 * © Ivan Babanin (07.07.2007 9:43:42)
 * Project Galaxy. This part of code is strictly confidential.
 */
public class Install {
    public static void install() {
//        LizardLogger.printlnStatement("DATABASE", "DATA", "check database existence");
//        if (!new File(SettingsStorage.getSettings().getDbFile()).exists()) {
//            LizardLogger.printlnStatement("DATABASE", "CREATE", "create default database");
//            try {
//                createDefaultUser();
//                Install.run();
//            } catch (Exception e) {
//                throw new ServiceException(e, true, "DATABASE", "INSTALL ERROR");
//            }
//        } else {
//            LizardLogger.printlnStatement("DATABASE", "database GALAXY found");
//        }
    }

    public static void run() throws Exception {
        SystemUser adminUser = new SystemUser();
        adminUser.setAdmin(true);
        adminUser.setId(0L);
        adminUser.setLastLogin(new Date());
        adminUser.setLogin("God");
        adminUser.setPassword(MD5.crypt("iddqd"));

        ServiceDataSource.getInstance().persist(adminUser);
    }
}

